<?php




namespace app\common\dao\user;


use app\common\dao\BaseDao;
use app\common\model\user\UserTalent;
use think\db\BaseQuery;

/**
 * Class FeedbackDao
 * @package app\common\dao\user
 * @author xaboy
 * @day 2020/5/28
 */
class UserTalentDao extends BaseDao
{

    /**
     * @return string
     * @author xaboy
     * @day 2020/5/28
     */
    protected function getModel(): string
    {
        return UserTalent::class;
    }

    /**
     * @param array $where
     * @return BaseQuery
     * @author xaboy
     * @day 2020/5/28
     */
    public function search(array $where)
    {
        return UserTalent::getDB()->when(isset($where['uid']) && $where['uid'] !== '', function ($query) use ($where) {
            $query->where('uid', $where['uid']);
        })->when(isset($where['keyword']) && $where['keyword'] !== '', function ($query) use ($where) {
            $query->where('real_name','like', '%'.$where['keyword'].'%')->whereOr('phone','like', '%'.$where['keyword'].'%')->whereOr('company','like', '%'.$where['keyword'].'%');
        })->order('create_time DESC');
    }

    /**
     * @param $id
     * @param $uid
     * @return bool
     * @author xaboy
     * @day 2020/5/28
     */
    public function uidExists($id, $uid): bool
    {
        return UserTalent::getDB()->where($this->getPk(), $id)->where('uid', $uid)->count($this->getPk()) > 0;
    }

    public function merExists(int $id)
    {
        return $this->getModel()::getDB()->where($this->getPk(), $id)->count() > 0;
    }
}
